//
//  WyLnadViewController.m
//  WY_Water
//
//  Created by wangyang on 2019/12/26.
//  Copyright © 2019 wangyang. All rights reserved.
//

#import "WyLnadViewController.h"
#import "ChildTagController.h"
#import "ChildNavigation.h"
#import "RJNavigationBar.h"
#import "Secview.h"

@interface WyLnadViewController ()<UIScrollViewDelegate>
@property (nonatomic,strong) UIScrollView   *WyScrollView;
@property (nonatomic, strong)RJNavigationBar *NvigationBar;
@end

@implementation WyLnadViewController

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    [self.NvigationBar showCustomNavigationBar:YES];
}
//隐藏
-(void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];

   [self.navigationController setNavigationBarHidden:NO animated:animated];
    [self.NvigationBar showCustomNavigationBar:NO];
}
//检测
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CGFloat offsetY = scrollView.contentOffset.y;
    CGFloat coloroffset = offsetY/ 64;
    coloroffset = coloroffset > 1?1:coloroffset;
    [self.NvigationBar setupBgColorAlpha:coloroffset animation:0.4 compeleteBlock:^{
        
    }];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = UIColorFromRGB(0xFAFAFA);
    [self.view addSubview:self.WyScrollView];
    
    self.NvigationBar = [RJNavigationBar createCustomNavigationBar];
      self.NvigationBar.title = @"登陆";
    self.NvigationBar.titleColor = WyBlackColor;
      
                        __weak typeof(self) weakSelf  = self;
                        weakSelf.NvigationBar.clickleftItemBlock = ^{
                 
                            [self leftselector];
//                            [self.navigationController popViewControllerAnimated:YES];
                            NSLog(@"点击返回按钮");
                        };
                        weakSelf.NvigationBar.clickrightItemBlock = ^{
                            Secview *se =[[Secview alloc] init];
                            [self.navigationController pushViewController:se animated:YES];
                        };
                        [self.view addSubview:self.NvigationBar];
    
    
    
    [self initSetUI];
    
}
-(void)leftselector
{
    if (self.LandVcBlock) {
        self.LandVcBlock();
    }
    [self.navigationController popViewControllerAnimated:YES];
}



-(void)initSetUI{
    
    
    
    
        for (int i = 0 ; i<self.WyTextFieldArray.count; i++) {


            UIView *WhitheView = [[UIView alloc]init];
            [self.WyScrollView addSubview:WhitheView];
            WhitheView.layer.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0].CGColor;
            WhitheView.layer.cornerRadius = 25;
            WhitheView.layer.shadowColor = [UIColor colorWithRed:209/255.0 green:209/255.0 blue:209/255.0 alpha:0.55].CGColor;
            WhitheView.layer.shadowOffset = CGSizeMake(0,2);
            WhitheView.layer.shadowOpacity = 1;
            WhitheView.layer.shadowRadius = 6;
            [WhitheView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.size.equalTo(CGSizeMake(WySCREENWIDTH-BiLiWidth(30), BiLiWidth(50)));
                make.top.mas_offset(BiLiWidth(430)+BiLiWidth(70)*i);
                make.centerX.mas_offset(BiLiWidth(0));
            }];
            
            UIImageView *img = [UIImageView imageWithImgName:self.ImgArray[i] superView:WhitheView];
            [img mas_makeConstraints:^(MASConstraintMaker *make) {
                make.size.equalTo(CGSizeMake(BiLiWidth(20), BiLiWidth(20)));
                make.top.equalTo(WhitheView.bottom).offset(BiLiWidth(-35));
                make.left.mas_offset(BiLiWidth(19));
            }];
            
            
              UITextField * WyTextField = [[UITextField alloc]init];
              [WhitheView addSubview:WyTextField];
              WyTextField.placeholder = self.WyTextFieldArray[i];
               WyTextField.textColor = [UIColor blackColor];
              [WyTextField mas_makeConstraints:^(MASConstraintMaker *make) {
                  make.size.equalTo(CGSizeMake(BiLiWidth(200), BiLiWidth(20)));
                  make.top.equalTo(WhitheView.bottom).offset(BiLiWidth(-35));
                  make.left.equalTo(img.right).offset(BiLiWidth(10));
              }];
              WyTextField.tag = i;

              if (WyTextField.tag == 0) {

                  _WyPhoneTextField = WyTextField;

              }
              else
              {
                  _WyPasswTextField = WyTextField;
              }

          }
    
    
      
    
    
          
          
            GGVerifyCodeViewBtn *WyCodeBtn = [[GGVerifyCodeViewBtn alloc]init];
             //  设置frame 这里我是按照自己需求来
             [self.BackImg addSubview:WyCodeBtn];
             [WyCodeBtn addTarget:self action:@selector(codeBtnVerification) forControlEvents:UIControlEventTouchUpInside];
             self.WyCodeBtn = WyCodeBtn;
             [WyCodeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                 make.size.equalTo(CGSizeMake(BiLiWidth(80), BiLiWidth(30)));
                 make.top.equalTo(self.WyPasswTextField.bottom).offset(BiLiWidth(20));
                 make.right.mas_offset(BiLiWidth(-15));
             }];


    
    

              _WylandBtn = [UIButton buttonWithType:UIButtonTypeCustom];
             [self.BackImg addSubview:_WylandBtn];
             [_WylandBtn setTitle:@"登陆" forState:0];
             [_WylandBtn setTitleColor:WyWhiteColor forState:0];
             [_WylandBtn addTarget:self action:@selector(Wyselector) forControlEvents:UIControlEventTouchUpInside];
             [_WylandBtn setBackgroundColor:UIColorFromRGB(0xFADB14)];
             WyViewRadius(_WylandBtn, BiLiWidth(25));
             [_WylandBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                 make.size.equalTo(CGSizeMake(WySCREENWIDTH-BiLiWidth(30), BiLiWidth(50)));
                 make.top.equalTo(self.WyCodeBtn.bottom).offset(BiLiWidth(30));
                 make.centerX.mas_offset(0);
             }];
    
}
-(void)codeBtnVerification
{
    [self.WyCodeBtn timeFailBeginFrom:60];
}

-(void)Wyselector

{
    if (_WyPhoneTextField.text.length == 0) {
        
        UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"信息提示"
                                                                       message:@"手机号不能为空"
                                                                preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive
                                                              handler:^(UIAlertAction * action) {
                                                                  //响应事件
                                                                  NSLog(@"action = %@", action);
                                                              }];
        UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault
                                                             handler:^(UIAlertAction * action) {
                                                                 //响应事件
                                                                 NSLog(@"action = %@", action);
                                                             }];
        
        [alert addAction:defaultAction];
        [alert addAction:cancelAction];
        [self presentViewController:alert animated:YES completion:nil];
        
    }
    if (_WyPasswTextField.text.length == 0) {
        UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"信息提示"
                                                                       message:@"验证码不能为空"
                                                                preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive
                                                              handler:^(UIAlertAction * action) {
                                                                  //响应事件
                                                                  NSLog(@"action = %@", action);
                                                              }];
        UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault
                                                             handler:^(UIAlertAction * action) {
                                                                 //响应事件
                                                                 NSLog(@"action = %@", action);
                                                             }];
        
        [alert addAction:defaultAction];
        [alert addAction:cancelAction];
        [self presentViewController:alert animated:YES completion:nil];
    }
    if (_WyPhoneTextField.text.length < 11 && _WyPasswTextField.text.length > 6) {
        UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"信息提示"
                                                                       message:@"请输入十一位有效数字"
                                                                preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive
                                                              handler:^(UIAlertAction * action) {
                                                                  //响应事件
                                                                  NSLog(@"action = %@", action);
                                                              }];
        UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault
                                                             handler:^(UIAlertAction * action) {
                                                                 //响应事件
                                                                 NSLog(@"action = %@", action);
                                                             }];
        
        [alert addAction:defaultAction];
        [alert addAction:cancelAction];
        [self presentViewController:alert animated:YES completion:nil];
    }
    
    if ([_WyPhoneTextField.text isEqualToString:@"15093357325"]&&[_WyPasswTextField.text isEqualToString:@"320320"]) {
        [WyEngineering sharedUser].user_phone = _WyPhoneTextField.text;
        [WyEngineering sharedUser].user_name = _WyPasswTextField.text;
        
        
        
        [MyProgressHUD showWithMaskType:MyProgressHUDMaskTypeBlack];
        [self performSelector:@selector(delayMethod) withObject:nil afterDelay:2.0];
        
    }else
    {
        UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"信息提示"
                                                                       message:@"请输入正确的账号和密码"
                                                                preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive
                                                              handler:^(UIAlertAction * action) {
                                                                  //响应事件
                                                                  NSLog(@"action = %@", action);
                                                              }];
        UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault
                                                             handler:^(UIAlertAction * action) {
                                                                 //响应事件
                                                                 NSLog(@"action = %@", action);
                                                             }];
        
        [alert addAction:defaultAction];
        [alert addAction:cancelAction];
        [self presentViewController:alert animated:YES completion:nil];
    }
}
-(void)delayMethod
{
    [MyProgressHUD dismiss];
    
    [self.navigationController popViewControllerAnimated:YES];
    
//    WyTabBarVc *leftNav = [[WyTabBarVc alloc] init];
//    [UIApplication sharedApplication].keyWindow.rootViewController = leftNav;
    
}


- (UIScrollView *)WyScrollView {
    
    if (!_WyScrollView) {
        _WyScrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
        [self.view addSubview:_WyScrollView];
        _WyScrollView.userInteractionEnabled = YES;
        _WyScrollView.delegate = self;
        _WyScrollView.showsVerticalScrollIndicator = NO;
        _WyScrollView.contentSize = CGSizeMake(WySCREENWIDTH, WySCREENHEIGHT*1.5);
        [_WyScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.bottom.mas_offset(0);
        }];
        if (@available(iOS 11.0, *)) {
            
            self.WyScrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }
        
        
        [self BackImg];
        
    }
    return _WyScrollView;
}


-(UIImageView *)BackImg

{
    
    if (!_BackImg) {
        
        _BackImg = [UIImageView imageWithImgName:@"登陆背景" superView:self.WyScrollView];
        _BackImg.userInteractionEnabled = YES;
        [_BackImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.equalTo(CGSizeMake(WySCREENWIDTH, WySCREENHEIGHT));
            make.top.mas_offset(0);
            make.left.mas_offset(0);
        }];
        
        
        
    }
    
    return _BackImg;
    
}







-(NSArray *)WyTextFieldArray

{
    if (!_WyTextFieldArray) {
        
        
        _WyTextFieldArray = [NSArray arrayWithObjects:@"请输入手机号",@"请输入验证码", nil];
        
    }
    
    return _WyTextFieldArray;
}

-(NSArray *)ImgArray

{
    
    if (!_ImgArray) {
        
       _ImgArray  = @[@"手机号",@"验证码"];
        
    }
    
    return _ImgArray;
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
